﻿using System;
using System.Net;

namespace Utility
{
    public static class HttpWebResponseExtensions
    {
        private static DateTime? GetHeaderDateTime(this HttpWebResponse response, HttpResponseHeader header)
        {
            DateTime? expires = response.Headers[header].ToNullableDateTime();
            if (expires.HasValue)
                expires = expires.Value.ToUniversalTime();
            return expires;
        }

        public static DateTime? GetExpires(this HttpWebResponse response)
        {
            return response.GetHeaderDateTime(HttpResponseHeader.Expires);
        }

        public static DateTime? GetLastModified(this HttpWebResponse response)
        {
            return response.GetHeaderDateTime(HttpResponseHeader.LastModified);
        }

        public static string GetETag(this HttpWebResponse response)
        {
            return response.Headers[HttpResponseHeader.ETag];
        }
    }
}
